Skip to content

feat(ai): change type of experimental_context from unknown to generic#13102

Merged
lgrammel merged 59 commits intomainfrom
lg/GJysF7Eo
Apr 2, 2026
Merged

feat(ai): change type of experimental_context from unknown to generic#13102
lgrammel merged 59 commits intomainfrom
lg/GJysF7Eo

Conversation

@lgrammel
Copy link
Copy Markdown
Collaborator

@lgrammel lgrammel commented Mar 5, 2026

Background

experimental_context for tools and step preparation was introduced in an earlier release without typing (type: unknown). Before marking context as stable, it should support smart generic typing for usage in tools, prepareStep, and telemetry.

Summary

Introduce generics on experimental_context. Each tool has a contextSchema for the tool-specific context. The context on the AI function call is a union of the tool contexts and can have additional properties for prepareStep and telemetry.

Limitations

The experimental_context setting is optional even when a context is needed, i.e. it will not throw type validation errors unless a context is specified.

Manual Verification

  • run and check types on examples/ai-functions/src/generate-text/openai/tool-call-with-context.ts
  • run and check types on examples/ai-functions/src/stream-text/openai/tool-call-with-context.ts
  • run and check types on examples/ai-functions/src/agent/openai/generate-context.ts
  • run and check types on examples/ai-functions/src/agent/openai/generate-context-call-options.ts

Tasks

  • prototype generic context and tool context merging
  • investigate type errors
  • implement generateText
  • implement streamText
  • implement agent / tool loop agent
  • figure out support in provider-defined tools
  • add type tests
  • add jsdoc
  • update reference documentation
  • update context documentation
  • update examples in docs that use context
  • update migration guide
  • remove prototypes
  • better name for ExpandedContext
  • self-review pr
  • changeset

Future Work

  • mark experimental_context stable
  • add sanitizeContext function
  • add tool context wrapper for name mapping and safety
  • add context to StopCondition parameters
  • move ToolSet into provider-utils package
  • investigate how to fix context optionality limitation
  • remove ToolCallOptions type

@tigent tigent Bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request labels Mar 5, 2026
lgrammel added 2 commits March 5, 2026 17:18
This reverts commit 50c741f.
- Introduced detailed JSDoc comments for `StaticToolCall`, `DynamicToolCall`, and `TypedToolCall` types.
- Clarified the purpose and usage of each type in the context of tool calls and their input schemas.
@lgrammel lgrammel marked this pull request as ready for review April 2, 2026 13:54
@lgrammel lgrammel merged commit 986c6fd into main Apr 2, 2026
18 checks passed
@lgrammel lgrammel deleted the lg/GJysF7Eo branch April 2, 2026 14:07
@vercel-ai-sdk
Copy link
Copy Markdown
Contributor

vercel-ai-sdk Bot commented Apr 2, 2026

🚀 Published in:

Package Version
ai 7.0.0-beta.57
@ai-sdk/alibaba 2.0.0-beta.13
@ai-sdk/amazon-bedrock 5.0.0-beta.17
@ai-sdk/angular 3.0.0-beta.57
@ai-sdk/anthropic 4.0.0-beta.13
@ai-sdk/assemblyai 3.0.0-beta.9
@ai-sdk/azure 4.0.0-beta.18
@ai-sdk/baseten 2.0.0-beta.11
@ai-sdk/black-forest-labs 2.0.0-beta.8
@ai-sdk/bytedance 2.0.0-beta.8
@ai-sdk/cerebras 3.0.0-beta.11
@ai-sdk/cohere 4.0.0-beta.9
@ai-sdk/deepgram 3.0.0-beta.8
@ai-sdk/deepinfra 3.0.0-beta.11
@ai-sdk/deepseek 3.0.0-beta.10
@ai-sdk/elevenlabs 3.0.0-beta.8
@ai-sdk/fal 3.0.0-beta.8
@ai-sdk/fireworks 3.0.0-beta.11
@ai-sdk/gateway 4.0.0-beta.28
@ai-sdk/gladia 3.0.0-beta.8
@ai-sdk/google 4.0.0-beta.20
@ai-sdk/google-vertex 5.0.0-beta.27
@ai-sdk/groq 4.0.0-beta.11
@ai-sdk/huggingface 2.0.0-beta.11
@ai-sdk/hume 3.0.0-beta.8
@ai-sdk/klingai 4.0.0-beta.9
@ai-sdk/langchain 3.0.0-beta.57
@ai-sdk/llamaindex 3.0.0-beta.57
@ai-sdk/lmnt 3.0.0-beta.8
@ai-sdk/luma 3.0.0-beta.8
@ai-sdk/mcp 2.0.0-beta.12
@ai-sdk/mistral 4.0.0-beta.10
@ai-sdk/moonshotai 3.0.0-beta.11
@ai-sdk/open-responses 2.0.0-beta.10
@ai-sdk/openai 4.0.0-beta.18
@ai-sdk/openai-compatible 3.0.0-beta.11
@ai-sdk/otel 1.0.0-beta.3
@ai-sdk/perplexity 4.0.0-beta.11
@ai-sdk/prodia 2.0.0-beta.11
@ai-sdk/provider-utils 5.0.0-beta.8
@ai-sdk/react 4.0.0-beta.57
@ai-sdk/replicate 3.0.0-beta.9
@ai-sdk/revai 3.0.0-beta.9
@ai-sdk/rsc 3.0.0-beta.58
@ai-sdk/svelte 5.0.0-beta.57
@ai-sdk/togetherai 3.0.0-beta.11
@ai-sdk/valibot 3.0.0-beta.8
@ai-sdk/vercel 3.0.0-beta.11
@ai-sdk/vue 4.0.0-beta.57
@ai-sdk/xai 4.0.0-beta.19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants